<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>gda-sql: GNOME Data Access 5 manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="GNOME Data Access 5 manual">
<link rel="up" href="part_tools.html" title="Part IV. GDA Tools">
<link rel="prev" href="libgda-tools-introduction.html" title="Introduction">
<link rel="next" href="libgda-tools-list-config.html" title="gda-list-config-5.0">
<meta name="generator" content="GTK-Doc V1.32 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="part_tools.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="libgda-tools-introduction.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="libgda-tools-list-config.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="libgda-sql"></a><span class="command"><strong>gda-sql</strong></span>
</h2></div></div></div>
<p>
	The <span class="command"><strong>gda-sql</strong></span> tool is an interactive command line tool to run SQL commands and work
	with dictionaries. This tool has got several options, use the <code class="option">--help</code> option
	to list them all, or consult the man page (<span class="command"><strong>man gda-sql</strong></span>)
      </p>
<p>
	For example to list the installed providers, do:
	</p>
<pre class="programlisting">
[prompt]&gt; gda-sql -L
                                     Installed providers list
Provider       | Description                                                                        
---------------+------------------------------------------------------------------------------------
Berkeley-DB    | Provider for Berkeley databases                                                    
Firebird       | Provider for Firebird databases                                                    
FirebirdEmbed  | Provider for embedded Firebird databases                                           
Ldap           | Provider for database where tables are based on data contained in an LDAP directory
MSAccess       | Provider for Microsoft Access files
[...]
	</pre>
<p>
	To list the configured data sources (DSN):
	</p>
<pre class="programlisting">
[prompt]&gt; gda-sql -l
                                                    List of defined data sources
DSN       | Provider | Description                          | Connection string            | Username | Global
----------+----------+--------------------------------------+------------------------------+----------+-------
SalesTest | SQLite   | Test database for a sales department | DB_DIR=/adir;DB_NAME=data.db |          | FALSE
[...]
	</pre>
<p>
	To run an interactive session, just specify a DSN or a connection string using
	the "&lt;provider&gt;://&lt;connection string&gt;" 
	format (such as for example "Firebird://DATABASE=/path/to/dbfile.fdb"), or set
	the GDA_SQL_CNC environment variable to contain that string, and run the command without any argument, 
	for example:
	</p>
<pre class="programlisting">
[prompt]&gt; gda-sql PostgreSQL://DB_NAME=sales
Welcome to the GDA SQL console, version 3.99.3

Type: .copyright to show usage and distribution terms
      .? for help with internal commands
      .q (or CTRL-D) to quit
      (the '.' can be replaced by a '\')
      or any query terminated by a semicolon

Opening connection 'c0' for: PostgreSQL://DB_NAME=sales
        Getting database schema information, this may take some time... Done.
c0&gt;
	</pre>
<p>
	Note that the "c0" is the prompt for the first opened connection.
      </p>
<p>
	Several connections can be opened at once (with only one "active" at any given time), by specifying
	all of them on the command line, or by using the <code class="option">\c</code>
	and <code class="option">\close</code> to manage (open, change, close) the connections; the prompt contains
	the name of the current connection used. The following example opens two connections, one for the "pgsales"
	DSN, and one for the "PostgreSQL://DB_NAME=sales" connection string, and shows the usage of the ".c" command
	to list the opened connections:
	</p>
<pre class="programlisting">
[prompt]&gt; gda-sql-5.0 pgsales PostgreSQL://DB_NAME=sales
Welcome to the GDA SQL console, version 3.99.3

Type: .copyright to show usage and distribution terms
      .? for help with internal commands
      .q (or CTRL-D) to quit
      (the '.' can be replaced by a '\')
      or any query terminated by a semicolon

Opening connection 'pgsales' for: pgsales
Opening connection 'c1' for: PostgreSQL://DB_NAME=sales
        Getting database schema information, this may take some time... Done.
c1&gt; .c
             List of opened connections
Name    | Provider   | DSN or connection string | Username
--------+------------+--------------------------+---------
pgsales | PostgreSQL | pgsales                  |         
c1      | PostgreSQL | DB_NAME=sales            |         
(2 rows)

c1&gt;
	</pre>
<p>
      </p>
<p>
	Here is another sample session showing how to use variables in statements:
	</p>
<pre class="programlisting">
[prompt]&gt; gda-sql-5.0 -p SQLite -c "DB_DIR=.;DB_NAME=sales_test"
Welcome to the GDA SQL console, version 3.1.2

Type: \copyright to show usage and distribution terms
      \? for help with internal commands
      \q (or CTRL-D) to quit
      or any query terminated by a semicolon

c0&gt; select * from customers;
id | name            | default_served_by | country | city
---+-----------------+-------------------+---------+-----
 2 | Ed Lamton       |                 4 | SP      | MDR 
 3 | Lew Bonito      |                 1 | FR      | TLS 
 4 | Mark Lawrencep  |              NULL | SP      | MDR 
 9 | Greg Popoff     |                 2 | SP      | MDR 
10 | Vladimir Zirkov |                 4 | NULL    | NULL
c0&gt; \set the_id 9
c0&gt; select * from customers where id= ##the_id;
id | name        | default_served_by | country | city
---+-------------+-------------------+---------+-----
 9 | Greg Popoff |                 2 | SP      | MDR 
c0&gt; 
	</pre>
<p>
      </p>
<p>
	See the <a class="link" href="gda-sql.html" title="Part VII. Gda SQL console's user manual">Gda SQL console tool manual section</a> for more information.
      </p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.32</div>
</body>
</html>